﻿using CuoiHoi.Business;
using System;
using System.IO;
using System.Web.Services;
using System.Web.UI;
namespace CuoiHoi.Admin
{
    public partial class Home1 : System.Web.UI.Page
    {
        public string idpage = "";
        public int Quyen = 0;

        void ThongBao(string Loi)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Thông báo!", "<script>alert('" + Loi + "')</script>", false);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (Session["TenNV"] == null)
                Response.Redirect("~/Admin/login.aspx");
            else
            {
                int IdNhanVien = int.Parse(Session["idNhanVien"].ToString());
                Quyen = BNhanVien.SelectByID(IdNhanVien).idChucVu;
                txtTenNguoiDung.InnerText = BNhanVien.SelectByID(IdNhanVien).TenNhanVien.ToString();               
                Avata.ImageUrl = "~/images/"+ BNhanVien.SelectByID(IdNhanVien).AnhDaiDien.ToString();

                Response.Cookies["x"].Value = "cookie";

                if (Request.QueryString["idpage"] != null)
                {
                    idpage = Request.QueryString["idpage"].ToString();

                    if (idpage == "vb")
                        PlaceHolder1.Controls.Add(LoadControl("ucVietBai.ascx"));
                    else
                        if (idpage == "qlha")
                            PlaceHolder1.Controls.Add(LoadControl("ucQuanLyAlbumAnh.ascx"));
                        else
                            if (idpage == "qltt")
                                PlaceHolder1.Controls.Add(LoadControl("ucQuanLyTinTuc.ascx"));
                            else
                                if (idpage == "qlstt")
                                    PlaceHolder1.Controls.Add(LoadControl("ucQuanLySuaTinTuc.ascx"));
                                else
                                    if (idpage == "tab")
                                        PlaceHolder1.Controls.Add(LoadControl("ucThemAlbum.ascx")); //
                                    else
                                        if (idpage == "qltl")
                                            PlaceHolder1.Controls.Add(LoadControl("ucQLTheLoai.ascx"));
                                        else
                                            if (idpage == "qlsl")
                                                PlaceHolder1.Controls.Add(LoadControl("ucSlider.ascx"));
                                            else
                                                if (idpage == "qlnv")
                                                    PlaceHolder1.Controls.Add(LoadControl("ucQuanLyNhanVien.ascx"));
                                                else
                                                    if (idpage == "qlcv")
                                                        PlaceHolder1.Controls.Add(LoadControl("ucQuanLyChucVu.ascx"));
                                                    else
                                                        if (idpage == "ttnd")
                                                            PlaceHolder1.Controls.Add(LoadControl("ucThongTinNguoiDung.ascx"));
                                                        else
                                                            if (idpage == "qlc")
                                                                PlaceHolder1.Controls.Add(LoadControl("ucQuanLyChat.ascx"));
                }
            }
        }

        [WebMethod]
        public static void XoaHinhAnh(int idHinhAnh)
        {
            string DuongDan = System.Web.HttpContext.Current.Server.MapPath("~/images/")+BHinhAnh.SelectByID(idHinhAnh).DuongDanHinh;
            if (File.Exists(DuongDan))
            {
                File.Delete(DuongDan);
            }
            BHinhAnh.Delete(idHinhAnh);
        }

        protected void btThoat_Click(object sender, EventArgs e)
        {
            Session["TenNV"] = null;
            Response.Cookies["pass"].Expires = DateTime.Now;
            Response.Cookies["userName"].Expires = DateTime.Now;
            Response.Redirect("~/Admin/login.aspx");
        }
    }
}
